using System;
using System.Collections.Generic;
using System.Text;

namespace Axe.Patterns
{
    public delegate void ParametrizedAction<T,U>(T target,U param);

    public sealed class ParametrizedActionProxy<T,U>
    {
        private ParametrizedAction<T,U> RealActionMethod;
        private U mParam;

        private void ActionMethodStub(T target)
        {
            RealActionMethod(target,mParam);
        }

        #region public Action<T> actionMethod
        /// <summary>
        /// Gets the action method.
        /// </summary>
        /// <value>The action method.</value>
        public Action<T> ActionMethod
        {
            get
            {
                return ActionMethodStub;
            }
        } 
        #endregion

        #region public ParametrizedAction<T,U> TargetMethod
        /// <summary>
        /// Gets or sets the target method.
        /// </summary>
        /// <value>The target method.</value>
        public ParametrizedAction<T, U> TargetMethod
        {
            get
            {
                return RealActionMethod;
            }
            set
            {
                RealActionMethod = value;
            }
        } 
        #endregion

        #region public U Parameter
        /// <summary>
        /// Gets or sets the parameter.
        /// </summary>
        /// <value>The parameter.</value>
        public U Parameter
        {
            get
            {
                return mParam;
            }
            set
            {
                mParam = value;
            }
        } 
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="ParametrizedActionProxy&lt;T, U&gt;"/> class.
        /// </summary>
        public ParametrizedActionProxy()
        {

        }

        public ParametrizedActionProxy(ParametrizedAction<T,U> act)
        {
            TargetMethod = act;
        }

        public ParametrizedActionProxy(ParametrizedAction<T, U> act, U param)
        {
            TargetMethod = act;
            Parameter = param;
        }

        public static implicit operator Action<T>(ParametrizedActionProxy<T,U> act)
        {
            return act.ActionMethod;
        }
    }
}
